<?php

class Madmin extends CI_Model {

    function __construct() {
        parent::__construct();
    }
    function  gettintuc(){
        $query = $this->db->get('topic_news');
        return $query->result();
    }
            function getmenu() {
        $query = $this->db->get('category');
        return $query->result();
    }

    function getsubmenu() {
        $query = $this->db->get('sub_category');
        return $query->result();
    }
    function xoasubchuyenmuc($idsubchuyenmuc){
        $this->db->delete('sub_category', array('sub_category_id' => $idsubchuyenmuc));
        return $this->db->affected_rows();
    }
    function xoachuyenmuc($idchuyenmuc) {
        $this->db->delete('category', array('category_id' => $idchuyenmuc));
        return $this->db->affected_rows();
    }
    function getidsuasub($idsua){
         $this->db->where('sub_category_id', $idsua);
        $query = $this->db->get("sub_category");
        return $query->result();
    }
            function getidsua($idsua) {
        $this->db->where('category_id', $idsua);
        $query = $this->db->get("category");
        return $query->result();
    }
        function suasubchuyenmuc($sub_category_name, $sub_category_desc, $opchuyenmuc, $sub_category_links, $status, $id){
            $data = array(
                'sub_category_name' => $sub_category_name,
                'sub_category_desc' => $sub_category_desc,
                'sub_category_links' =>$sub_category_links,
                'sub_category_status' => $status,
                'category_id' =>  $opchuyenmuc
            );
            $this->db->where('sub_category_id', $id);
            $this->db->update('sub_category', $data); 
  return $this->db->affected_rows();
        }
            function suachuyenmuc($category_name, $category_desc, $class, $category_links, $status,$id) {
        $data = array(
               'category_name' => $category_name,
               'category_desc' => $category_desc,
               'class' => $class,
                'category_links' => $category_links,
                'category_status' => $status
            );
        $this->db->where('category_id', $id);
        $this->db->update('category', $data); 
  return $this->db->affected_rows();
    }
    function themsubchuyenmuc($sub_category_name, $sub_category_desc, $opchuyenmuc, $sub_category_links, $status){
        $data = array(
            'sub_category_name' => $sub_category_name,
                'sub_category_desc' => $sub_category_desc,
                'sub_category_links' =>$sub_category_links,
                'sub_category_status' => $status,
                'category_id' =>  $opchuyenmuc
        );
                $this->db->insert('sub_category', $data); 
         return $this->db->affected_rows();
    }
    function themchuyenmuc($category_name, $category_desc, $class, $category_links, $status){
        $data = array(
     'category_name' => $category_name,
               'category_desc' => $category_desc,
               'class' => $class,
                'category_links' => $category_links,
                'category_status' => $status
                );
        $this->db->insert('category', $data); 
         return $this->db->affected_rows();
    }

}
